%%Difference plotter for NW and EW decoding probabilities
clear
clc
close all

y_lim_min =-1.5
y_lim_max = 1.3

y_ticks = 0.2;
y_max = 1.3;
y_min = -1.3;


%%%%%%%%NEW
num_sim = 10000
%Load the simulated data
L1_30_sim = load('data_points_L1_NEW_g130.txt')/num_sim;
L1_50_sim = load('data_points_L1_NEW_g150.txt')/num_sim;
L1_40_sim = load('data_points_L1_NEW_g140.txt')/num_sim;
L2_30_sim = load('data_points_L2_NEW_g130.txt')/num_sim;
L2_50_sim = load('data_points_L2_NEW_g150.txt')/num_sim;
L2_40_sim = load('data_points_L2_NEW_g140.txt')/num_sim;


%Load the analytically calculated data
L1_g_30_anal = load('saved_data_new/new_anal_L1_g3f_2.txt');
L2_g_30_anal = load('saved_data_new/new_anal_L2_g3f_2.txt');
L1_g_50_anal = load('saved_data_new/new_anal_L1_g5f_2.txt');
L2_g_50_anal = load('saved_data_new/new_anal_L2_g5f_2.txt');
L1_g_40_anal = load('saved_data_new/new_anal_L1_g4f_2.txt');
L2_g_40_anal = load('saved_data_new/new_anal_L2_g4f_2.txt');




%NEW figure
fig1_new = figure
hold on
plot((transpose(L1_g_30_anal(2:185))-L1_30_sim(1:184))*100,'k');
plot((transpose(L1_g_40_anal(2:185))-L1_40_sim(1:184))*100,'--k');
plot(-100,-100,'-ok','MarkerSize',3.5);
plot((transpose(L1_g_50_anal(2:185))-L1_50_sim(1:184))*100,'-k');
%Business

label_1 = 'L1, \Gamma_1 0.3,NW';
label_2 = 'L1, \Gamma_1 0.4,NW';
label_3 = 'L1, \Gamma_1 0.5,NW';

legend_h = legend('','','');

set(legend_h,'String',[label_1;label_2;label_3],'location','SouthEast');
set(legend_h,'interpreter','tex');
xlabel('Total number of received packets [-]');
ylabel('Difference in decoding probability [pp]');
set(gca,'XTick',30:10:185,'xlim',[30 185]);
set(gca,'YTick',y_min:y_ticks:y_max,'ylim',[y_lim_min y_lim_max]);

plot(1:3:185,(transpose(L1_g_50_anal(2:3:185))-L1_50_sim(1:3:184))*100,'ok','MarkerSize',3.5);

grid()
pbaspect([2.5 1 1])
% Save plot
figname=strcat('l1_new_dif.eps');
print(gcf,'-depsc2',figname);
hold off










fig2_new = figure
hold on
plot((transpose(L2_g_30_anal(2:185))-L2_30_sim(1:184))*100,'-k');
plot((transpose(L2_g_40_anal(2:185))-L2_40_sim(1:184))*100,'--k');
plot(-100,-100,'-ok','MarkerSize',3.5);
plot((transpose(L2_g_50_anal(2:185))-L2_50_sim(1:184))*100,'-k');

%Business

label_1 = 'L2, \Gamma_1 0.3,NW';
label_2 = 'L2, \Gamma_1 0.4,NW';
label_3 = 'L2, \Gamma_1 0.5,NW';

legend_h = legend('','','');

set(legend_h,'String',[label_1;label_2;label_3],'location','SouthEast');
set(legend_h,'interpreter','tex');
xlabel('Total number of received packets [-]');
ylabel('Difference in decoding probability [pp]');
set(gca,'XTick',30:10:185,'xlim',[30 185]);
set(gca,'YTick',y_min:y_ticks:y_max,'ylim',[y_lim_min y_lim_max]);

plot(1:3:185,(transpose(L2_g_50_anal(2:3:185))-L2_50_sim(1:3:184))*100,'ok','MarkerSize',3.5);


grid()
pbaspect([2.5 1 1])
% Save plot
figname=strcat('l2_new_dif.eps');
print(gcf,'-depsc2',figname)
hold off









num_sim = 10000
%EW
%Load anal data

L1_g_30_anal_ew = load('/Users/benjamin/Documents/AAU/6.semester/P6trunk/plotting/uep_analytic/uep_ew_analytic_g1_03_g2_07.mat','l1_prob_1');
L2_g_30_anal_ew = load('/Users/benjamin/Documents/AAU/6.semester/P6trunk/plotting/uep_analytic/uep_ew_analytic_g1_03_g2_07.mat','l2_prob_1');
L1_g_30_anal_ew = L1_g_30_anal_ew.l1_prob_1;
L2_g_30_anal_ew = L2_g_30_anal_ew.l2_prob_1;


L1_g_40_anal_ew = load('/Users/benjamin/Documents/AAU/6.semester/P6trunk/plotting/uep_analytic/uep_ew_analytic_g1_04_g2_06.mat','l1_prob_1');
L2_g_40_anal_ew = load('/Users/benjamin/Documents/AAU/6.semester/P6trunk/plotting/uep_analytic/uep_ew_analytic_g1_04_g2_06.mat','l2_prob_1');
L1_g_40_anal_ew = L1_g_40_anal_ew.l1_prob_1;
L2_g_40_anal_ew = L2_g_40_anal_ew.l2_prob_1;

L1_g_50_anal_ew = load('/Users/benjamin/Documents/AAU/6.semester/P6trunk/plotting/uep_analytic/uep_ew_analytic_g1_05_g2_05.mat','l1_prob_1');
L2_g_50_anal_ew = load('/Users/benjamin/Documents/AAU/6.semester/P6trunk/plotting/uep_analytic/uep_ew_analytic_g1_05_g2_05.mat','l2_prob_1');
L1_g_50_anal_ew = L1_g_50_anal_ew.l1_prob_1;
L2_g_50_anal_ew = L2_g_50_anal_ew.l2_prob_1;


%Load sim data
L1_30_sim_ew = load('data_points_L1_EW_g130.txt')/num_sim;
L1_50_sim_ew = load('data_points_L1_EW_g150.txt')/num_sim;
L1_40_sim_ew = load('data_points_L1_EW_g140.txt')/num_sim;
L2_30_sim_ew = load('data_points_L2_EW_g130.txt')/num_sim;
L2_50_sim_ew = load('data_points_L2_EW_g150.txt')/num_sim;
L2_40_sim_ew = load('data_points_L2_EW_g140.txt')/num_sim;





%EW figure
fig1_ew = figure;
hold on
plot((transpose(L1_g_30_anal_ew(1:185))-L1_30_sim_ew(1:185))*100,'k')
plot((transpose(L1_g_40_anal_ew(1:185))-L1_40_sim_ew(1:185))*100,'--k')
plot(-100,-100,'-ok','MarkerSize',3.5);
plot((transpose(L1_g_50_anal_ew(1:185))-L1_50_sim_ew(1:185))*100,'-k')

%Business

label_1 = 'L1, \Gamma_1 0.3,EW';
label_2 = 'L1, \Gamma_1 0.4,EW';
label_3 = 'L1, \Gamma_1 0.5,EW';

legend_h = legend('','','');

set(legend_h,'String',[label_1;label_2;label_3],'location','SouthEast')
set(legend_h,'interpreter','tex');
xlabel('Total number of received packets [-]');
ylabel('Difference in decoding probability [pp]');
set(gca,'XTick',40:10:185,'xlim',[40 185])
set(gca,'YTick',y_min:y_ticks:y_max,'ylim',[y_lim_min y_lim_max])

plot(1:3:185,(transpose(L1_g_50_anal_ew(1:3:185))-L1_50_sim_ew(1:3:185))*100,'ok','MarkerSize',3.5);

grid()
pbaspect([2.5 1 1])
% Save plot
figname=strcat('l1_ew_dif.eps');
print(gcf,'-depsc2',figname)
hold off











%%%%L2 - EW


fig2_ew = figure;
hold on
plot((transpose(L2_g_30_anal_ew(1:185))-L2_30_sim_ew(1:185))*100,'k')
plot((transpose(L2_g_40_anal_ew(1:185))-L2_40_sim_ew(1:185))*100,'--k')
plot(-100,-100,'-ok','MarkerSize',3.5);
plot((transpose(L2_g_50_anal_ew(1:185))-L2_50_sim_ew(1:185))*100,'-k')
plot(1:3:185,(transpose(L2_g_50_anal_ew(1:3:185))-L2_50_sim_ew(1:3:185))*100,'ok','MarkerSize',3.5);


%Business

label_1 = 'L2, \Gamma_1 0.3,EW';
label_2 = 'L2, \Gamma_1 0.4,EW';
label_3 = 'L2, \Gamma_1 0.5,EW';

legend_h = legend('','','');

set(legend_h,'String',[label_1;label_2;label_3],'location','SouthEast')
set(legend_h,'interpreter','tex');
xlabel('Total number of received packets [-]');
ylabel('Difference in decoding probability [pp]');
set(gca,'XTick',40:10:185,'xlim',[40 185])
set(gca,'YTick',y_min:y_ticks:y_max,'ylim',[y_lim_min y_lim_max])


grid()
pbaspect([2.5 1 1])
% Save plot
figname=strcat('l2_ew_dif.eps');
print(gcf,'-depsc2',figname)

hold off



